var t, e = getApp(), a = require("../../../utils/util.js");

Page({
    data: {
        invite: !0
    },
    onLoad: function(e) {
        t = this, e.custId ? (wx.setStorageSync("shareCustId", e.custId), t.setData({
            invite: !1,
            addId: e.custId
        }), t.getShareUsrInfo()) : t.getcardHistory();
    },
    getShareUsrInfo: function() {
        var o = e.globalData.token;
        a.request(e, "wx/mkt/getSomeBodySend", "GET", {
            token: o,
            addId: t.data.addId
        }, function(e) {
            e.state && t.setData({
                nickName: e.data.nickName
            });
        });
    },
    getcardHistory: function() {
        var o = e.globalData.token;
        a.request(e, "wx/mkt/showReceiveRecord", "GET", {
            token: o
        }, function(e) {
            e.state && t.setData({
                history: e.data
            });
        });
    },
    onShareAppMessage: function(t) {
        return {
            title: "分享红包免费洗车",
            path: "/pages/info/share/index?custId=" + e.globalData.custId,
            success: function(t) {
                wx.showShareMenu({
                    withShareTicket: !0
                });
            },
            fail: function(t) {}
        };
    },
    searchCoupons: function() {
        wx.redirectTo({
            url: "/pages/info/coupons/index"
        });
    },
    getShareCoupons: function() {
        wx.removeStorageSync("shareCustId");
        var o = e.globalData.custId, n = e.globalData.token;
        a.request(e, "wx/mkt/getActivityById", "GET", {
            token: n,
            activityId: 1
        }, function(s) {
            s.state && (null != s.data ? a.request(e, "wx/mkt/receiveAutoCoupon", "GET", {
                token: n,
                addId: t.data.addId,
                custId: o
            }, function(t) {
                t.state ? (wx.removeStorageSync("shareCustId"), wx.showToast({
                    title: "领取成功"
                }), setTimeout(function() {
                    wx.switchTab({
                        url: "/pages/home/home"
                    });
                }, 2e3)) : wx.showToast({
                    title: "免费洗车券仅限新用户领取",
                    icon: "none"
                });
            }) : wx.showToast({
                title: "活动已结束",
                icon: "none"
            }));
        });
    }
});